﻿using FluentNHibernate.Mapping;
using AdventureWorks.Domain;
namespace AdventureWorks.DataAccess.Mappings
{
    public class PersonMapping : SubclassMap<Person>
    {
        public PersonMapping()
        {
            Schema("Person");
            Table("Person");
            Map(x => x.FirstName);
            Map(x => x.LastName);
            Map(x => x.Title);
            Map(x => x.Suffix);
            Map(x => x.MiddleName);
            Map(x => x.PersonType);
            HasMany<PhoneContact>(x => x.Phones).LazyLoad().KeyColumn("BusinessEntityId").Cascade.AllDeleteOrphan();
            HasMany(x => x.Emails).Table("EmailAddress").Schema("Person")
                .Element("EmailAddress").KeyColumn("BusinessEntityId")
                .Fetch.Select();
            KeyColumn("BusinessEntityId");
       }
    }
}
